package com.jweb.framework.core.util;

import java.io.FilterWriter;
import java.io.IOException;
import java.io.Writer;


public class FilterWriterB extends FilterWriter {
	
	protected char c[];
	
	protected FilterWriterB(Writer writer)
    {
        super(writer);
        c = null;
    }

    protected static final String a(char c1)
        throws IllegalArgumentException
    {
        if(c1 == '"')
            return "&quot;";
        if(c1 == '\'')
            return "&apos;";
        else
            throw new IllegalArgumentException((new StringBuilder("Unrecognized quote char ('")).append(c1).append(" [").append(c1).append("]; expected a single or double quote char").toString());
    }

    protected void a()
        throws IOException
    {
        throw new IOException("Null character in text to write");
    }

    protected final void a(int i)
        throws IOException
    {
        char ac[] = c;
        if(ac == null)
        {
            ac = new char[8];
            c = ac;
            ac[0] = '&';
            ac[1] = '#';
            ac[2] = 'x';
        }
        if(i < 16)
        {
            ac[3] = (char)(i >= 10 ? 87 + i : 48 + i);
            ac[4] = ';';
            out.write(ac, 0, 5);
        } else
        {
            for(int j = 6; j > 2; j--)
            {
                int k = i & 15;
                i >>= 4;
                ac[j] = (char)(k >= 10 ? 87 + k : 48 + k);
            }

            ac[7] = ';';
            out.write(ac, 0, 8);
        }
    }
	
}
